package camera

import org.lwjgl.input.Keyboard
import org.lwjgl.LWJGLException
import org.lwjgl.opengl.GL11._
import org.lwjgl.opengl.{GL11, DisplayMode, Display}
;

/**
 * Created by IntelliJ IDEA.
 * User: bilesja
 * Date: 4/24/11
 * Time: 3:02 PM
 * To change this template use File | Settings | File Templates.
 */
//Doesn't do anything yet!
class Camera() extends Application {
  	var x = 0f; var y = 0f; var z = 0f
	var theta = 0f; var phi = 0f; var angle3 = 0f;
  var zoom = 1f;

	var goingRight = false;
	var goingLeft = false;
	var goingUp = false
	var goingDown = false
	var thetaRight = false
	var thetaLeft = false
	var phiRight = false
	var phiLeft = false
  var angleRight = false
  var angleLeft = false
  var zoomIn = false
  var zoomOut = false

  var displaySize = 0f;
	def pollInput(){

		while (Keyboard.next()) {
		    if (Keyboard.getEventKeyState()) {
		        if (Keyboard.getEventKey() == Keyboard.KEY_A || Keyboard.getEventKey == Keyboard.KEY_LEFT) {goingLeft = true }
            if (Keyboard.getEventKey() == Keyboard.KEY_S || Keyboard.getEventKey() == Keyboard.KEY_DOWN) {goingDown = true}
            if (Keyboard.getEventKey() == Keyboard.KEY_D || Keyboard.getEventKey() == Keyboard.KEY_RIGHT) {goingRight = true}
            if (Keyboard.getEventKey() == Keyboard.KEY_W || Keyboard.getEventKey() == Keyboard.KEY_UP) {goingUp = true}
            if (Keyboard.getEventKey() == Keyboard.KEY_J) {thetaLeft = true}
            if (Keyboard.getEventKey() == Keyboard.KEY_L) {thetaRight = true}
            if (Keyboard.getEventKey() == Keyboard.KEY_I) {phiRight = true}
            if (Keyboard.getEventKey() == Keyboard.KEY_K) {phiLeft = true}
            if (Keyboard.getEventKey() == Keyboard.KEY_U) {angleLeft = true}
          if (Keyboard.getEventKey() == Keyboard.KEY_O) {angleRight = true}
          if (Keyboard.getEventKey() == Keyboard.KEY_Q) {zoomIn= true}
            if (Keyboard.getEventKey() == Keyboard.KEY_E) {zoomOut= true}

        } else {
		         if (Keyboard.getEventKey() == Keyboard.KEY_A || Keyboard.getEventKey == Keyboard.KEY_LEFT) {goingLeft = false}
            if (Keyboard.getEventKey() == Keyboard.KEY_S || Keyboard.getEventKey() == Keyboard.KEY_DOWN) {goingDown = false}
            if (Keyboard.getEventKey() == Keyboard.KEY_D || Keyboard.getEventKey() == Keyboard.KEY_RIGHT) {goingRight = false}
            if (Keyboard.getEventKey() == Keyboard.KEY_W || Keyboard.getEventKey() == Keyboard.KEY_UP) {goingUp = false}
            if (Keyboard.getEventKey() == Keyboard.KEY_J) {	thetaLeft = false}
          if (Keyboard.getEventKey() == Keyboard.KEY_L) {thetaRight = false}
          if (Keyboard.getEventKey() == Keyboard.KEY_I) {phiRight = false}
          if (Keyboard.getEventKey() == Keyboard.KEY_K) {phiLeft = false}
                      if (Keyboard.getEventKey() == Keyboard.KEY_U) {angleLeft = false}
          if (Keyboard.getEventKey() == Keyboard.KEY_O) {angleRight = false}
          if (Keyboard.getEventKey() == Keyboard.KEY_Q) {zoomIn= false}
            if (Keyboard.getEventKey() == Keyboard.KEY_E) {zoomOut= false}
		    }
		}
	}

  def drawBox(){
    pollInput
    if (goingLeft) x -= 15*zoom
    if (goingRight) x += 15*zoom
    if (goingUp) y += 15*zoom
    if (goingDown) y -= 15*zoom
    if (thetaRight) theta += 3*zoom
    if (thetaLeft) theta -= 3*zoom
    if (phiRight) phi += 3*zoom
    if (phiLeft) phi -= 3*zoom
    if (zoomIn) zoom *= 1.02f
    if (zoomOut) zoom *= 0.98f
    if (angleLeft) angle3 -= 3*zoom
    if (angleRight) angle3 += 3*zoom


    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();
    GL11.glOrtho(-displaySize*zoom, displaySize*zoom,-displaySize*zoom, displaySize*zoom, -20000, 20000);
    GL11.glTranslated(x,y,0)
    GL11.glRotatef(theta,0,1f,0)
    GL11.glRotatef(phi, 1f,0,0)
    GL11.glRotatef(angle3,0,0,1f)


    GL11.glMatrixMode(GL11.GL_MODELVIEW);
  }
}